﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
//using Chefbook.DataObjects;
using NUnit.Framework;
using Chefbook.UserActions;
using Rhino.Mocks;
using Chefbook.DataAccessLayer;

namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class RemoveRecipeFromCategoryActionFixture
    {
        private MockRepository mocks;
        private IUserAction action;
        private Category category;
        private Recipe recipe;
        private ChefbookEntities db;

        [SetUp]
        public void Init()
        {
            mocks = new MockRepository();
            db = new ChefbookEntities();

            category = new Category();
            recipe = new Recipe();


            Assert.Contains(category, recipe.Categories.ToList());
            Assert.Contains(recipe, category.DirectRecipes);

            action = new RemoveRecipeFromCategoryAction(recipe, category) { DatabaseConnector = db };
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.False(recipe.Categories.Contains(category),"Category not removed from Recipe");
            Assert.False(category.DirectRecipes.Contains(recipe), "Recipe not removed from Category");

        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.Contains(category, recipe.Categories.ToList());
            Assert.Contains(recipe, category.DirectRecipes.ToList());
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Remove Recipe '{0}' from Category '{1}'", recipe, category), action.ToString());
        }


    }
}
